import {createRouter, createWebHistory} from 'vue-router';
import store from "@/store/index.js";
import {ElMessage} from "element-plus";

const routes = [
	{
		path: '/',
		name: 'login',
		component: () => import('../views/ServiceTerminal/LoginView.vue')
	}, 
	{
		path: '/Community/:id',
		name: 'Community',
		component: () => import('@/views/DepartmentTerminal/DepartmentTerminalView.vue'),
		children: [{
			path: 'ActivityDetail/:aid',
			name: 'ActivityDetail',
			component: () => import('../components/DepartmentTerminal/SignInAttendance/dataDetails.vue'),
			props: true
		},]
	}, 
	{
		path: '/Admin',
		name: 'Admin',
		meta: {requiresAuth: true},
		component: () => import('../views/AdminTerminal/AdminTerminalView.vue'),
		children: [{
			path: 'UserManagement',
			name: 'UserManagement',
			component: () => import('../components/AdminTerminal/UserManagement/UserManagement.vue')
		}]
	}, 
	{
		path: '/Student/:id',
		name: 'Student',
		component: () => import('../views/StudentTerminal/StudentTerminalView.vue')
	}];

const router = createRouter({
	history: createWebHistory(),
	routes
});

// router.beforeEach((to, from, next) => {
// 	if (to.meta['requiresAuth']) {
// 		if (!store.state.CurrentUser) {
// 			ElMessage.error('请先登录');
// 			next({path: '/'});
// 		} else {
// 			if (store.state.CurrentUser === 3) {
// 				next();
// 			} else {
// 				ElMessage.error('非法用户!');
// 				next({path: '/'});
// 			}
// 		}
// 	} else {
// 		next();
// 	}
// });

export default router;
